<template>
    <div class="member-log-data">
        <el-table :data="memberLogTableData.filter(data => !searchMemberNum || data.memberNum.includes(searchMemberNum))"
            style="width: 100%" v-loading="tableLoader">

            <el-table-column label="日志ID" prop="logId" width="150" align="center">
            </el-table-column>

            <el-table-column label="成员ID" prop="memberId" width="150" align="center">
            </el-table-column>

            <el-table-column label="成员工号" prop="memberNum" width="150" align="center">
            </el-table-column>

            <el-table-column label="行为" prop="behavior" width="150" align="center" show-overflow-tooltip>
            </el-table-column>

            <el-table-column label="IP地址" prop="ipAddr" width="180" align="center">
            </el-table-column>

            <el-table-column label="记录时间" width="200" align="center">
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.logTime | dateFormat("yyyy-mm-dd hh:mm:ss") }}</span>
                </template>
            </el-table-column>

            <el-table-column label="操作" width="200" align="center">
                <template slot="header" slot-scope="scope">
                    <el-input prefix-icon="el-icon-search" v-model="searchMemberNum" size="big" placeholder="通过成员工号搜索" />
                </template>
                <template slot-scope="scope">
                    <el-button size="mini" type="danger" @click="handleDelete(scope.row.logId)"
                        icon="el-icon-delete">删除</el-button>
                </template>
            </el-table-column>

        </el-table>
        <!-- 每页5条 -->
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="queryMemberLogTableList" />
    </div>
</template>
  
<script>

import { queryMemberLogList, deleteMemberLog } from '@/api/memberLog'
import { Message } from 'element-ui'

export default {
    name: 'sysMemberLog',

    data() {
        return {
            memberLogTableData: null,
            tableLoader: false,
            queryParams: {
                pageNum: 1,
                pageSize: 5
            },
            total: 0,
            searchMemberNum: ''
        }
    },

    created() {
        this.tableLoader = true
        this.queryMemberLogTableList()
    },

    methods: {
        queryMemberLogTableList() {
            queryMemberLogList(this.queryParams).then((res) => {
                this.memberLogTableData = res.rows
                this.total = res.total
                this.tableLoader = false
            })
        },

        handleDelete(id) {
            this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                deleteMemberLog(id).then((res) => {
                    if (res.code === 200) {
                        Message.success('删除成功')
                        this.tableLoader = true
                        this.queryMemberLogTableList()
                    }
                })
            });
        }
    },
    filters: {
        dateFormat: function (val, args) {
            if (val) {
                var dt = new Date(val);
                var year = dt.getFullYear();
                var month = ("0" + (dt.getMonth() + 1)).slice(-2);
                var day = ("0" + dt.getDate()).slice(-2);
                if (args.toLowerCase() === "yyyy-mm-dd") {
                    return year + "-" + month + "-" + day;
                } else {
                    var hour = ("0" + dt.getHours()).slice(-2);
                    var min = ("0" + dt.getMinutes()).slice(-2);
                    var sec = ("0" + dt.getSeconds()).slice(-2);
                    return (
                        year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
                    );
                }
            } else {
                return '';
            }
        },
    },
}
</script>

<style lang="scss" scoped></style>